package xio.ccf_201512;

import java.util.Scanner;

/**
 * 201512-2 消除游戏
 * Created by ywb47 on 2017/10/3.
 */
public class EliminationGame {
    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        int M = s.nextInt();
        int N = s.nextInt();
        int[][] arr = new int[M][N];
        byte[][] flag = new byte[M][N]; //记录可被消除点的位置（可被消除置1）
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        //横向 纵向 后两位检查是否与本位相等满足消除条件
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (j + 1 < N && j + 2 < N) {
                    if ((arr[i][j] == arr[i][j + 1]) && (arr[i][j] == arr[i][j + 2])) {
                        flag[i][j] = 1;
                        flag[i][j + 1] = 1;
                        flag[i][j + 2] = 1;
                    }
                }
                if (i + 1 < M && i + 2 < M) {
                    if ((arr[i][j] == arr[i + 1][j]) && (arr[i][j] == arr[i + 2][j])) {
                        flag[i][j] = 1;
                        flag[i + 1][j] = 1;
                        flag[i + 2][j] = 1;
                    }
                }
            }
        }
        for (int i = 0; i < M; i++) {
            for (int j = 0; j < N; j++) {
                if (flag[i][j] == 1) {
                    arr[i][j] = 0;
                }
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
}
